home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cp1.zip / SHOWCH1.C < prev    next >
Text File  |  1993-05-26  |  3KB  |  74 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville MI
  3. Date: 05-23-93 (13:10)             Number: 8
  4. From: MATT GRASSE                  Refer#: NONE
  5.   To: JIM BURNS                     Recvd: NO  
  6. Subj: Ascii Boxes                    Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8. JB>little idea to write directly to the video board, but I'm
  9. JB>not sure it really works and then what about portability is
  10. JB>the color video address always xB8000 ?
  11.  
  12. Jim -
  13.    The video address will always be 0xB8000 unless you're using a
  14. monochrome display and then it would begin at 0xB0000.  Otherwise
  15. 0xB8000 will always point to the begining of the video memory on PCs
  16. Here's a simple function that should fill the screen with a character,
  17. wait for a keypress and then exit.
  18.  
  19. /********
  20.  *  This program is released to public domain and al that other good
  21.  *  stuff...
  22.  *  This is untested but it should work.
  23.  ********/
  24.  
  25. #define VID_ADDR  0xB8000000   /* value for far pointer to video mem */
  26. #define NORMAL    0x87         /* attribute value for normal text */
  27. #define ROWS      25
  28. #define COLS      80
  29.  
  30. void showch(unsigned char, unsigned char);
  31. main()
  32. ä
  33.    unsigned char ch, attirb;  /* the character and its attribute */
  34.                               /* keep theses unsigned or things  */
  35.                               /* may not look right */
  36.    printf("Enter a char");
  37.    ch = getch();
  38.    attrib = NORMAL;
  39.    showch(ch, attrib);
  40.    getch();
  41. å
  42.  
  43. /********
  44.  * showch() - this function fills the screen with the specified
  45.  *            character
  46.  **************/
  47. void showch(unsigned char ch, unsigned char attrib)
  48. ä
  49.    int far *farptr = (int far *)VID_ADDR;     /* to point to video memory */
  50.    int col, row;
  51.  
  52.    for(row = 0; row < ROWS; row++)
  53.       for(col=0; col < COLS; col++)
  54.          *(farptr + row*COLS + col) = ch ö attrib<<8;
  55. å
  56.  
  57. the final line calculates the memory address for a given row and column
  58. on the text screen.  Each char on the screen is represented by two bytes
  59. the attribute and then the char.  So attrib is shifted over 8 bits to
  60. put it at the begining of those two bytes and then ORed to the char.
  61. This should always work, it win't scroll the screen and it's fast.  If
  62. you're writing you're program with quickC (and probably some other
  63. compilers that allow you to run the program for the editor and then
  64. capture the output) you may have to run it rom the prompt to get it to
  65. run properly.  The only drawback to this method is I don't thibnk you can
  66. the output of this program if you run it from another.  If you need any more
  67. info drop me a line.
  68.  
  69. --- PTQWK 1.00 Beta-2 (Eval.)
  70.  * Origin: The Biggest Little BBS In Enon, Ohio! (1:110/270)
  71. SEEN-BY: 1/211 11/2 4 108/89 110/10 15 35 69 150 210 255 270 290 310 375
  72. SEEN-BY: 110/515 540 154/40 77 157/2 159/100 125 575 950 396/1 2270/1
  73. SEEN-BY: 2440/5
  74.